<?php
$paymentService = new PaymentServices();
$orderService = new OrdersService();
$fromEmail = $glb['contactEmail'];
$host = Tool::decode($smtp['host'], "sTunnInVietnAm@2012#");
$port = Tool::decode($smtp['port'], "sTunnInVietnAm@2012#");
$user = Tool::decode($smtp['user'], "sTunnInVietnAm@2012#");
$pass = Tool::decode($smtp['pass'], "sTunnInVietnAm@2012#");
$emailService = new EmailService($host, $port, $user, $pass);
$emailService->setSiteURL($glb['websiteURL']);
switch ($action) {
	case "pay":
		if($permit == true)
		{
			$paymentID = $_POST['paymentID'];
			$firstAmmount = $_POST['firstAmmount'];
			$needToPaid = $_POST['needToPaid'];
			$count = count($paymentID);
			for($i=0; $i<$count; $i++)
			{
				$balance = $needToPaid[$i]- Tool::convertMoneyToNumber($firstAmmount[$i]);
				$paymentService->updateFirstAmount($context, $result, $paymentID[$i], Tool::convertMoneyToNumber($firstAmmount[$i]), $balance);
			}
			$orderService->updateTypeByOrderID($context, $result, 4, $_POST['oderID']);
			header("Location:index.php?func=payment&opt=paymentList");
		}else
			header("Location:index.php?func=dash");
		break;
			
	case "payNext":
		if($permit == true)
		{
			$paymentID = $_GET['id'];
			$paymentService->updateIsDone($context, $result, $paymentID);
			header("Location:index.php?func=payment&opt=viewPayment&id=".$_GET['orderID']);
		}else
			header("Location:index.php?func=dash");
		break;
	case "searchPay":
		break;
	default:
		echo "khong co tinh nang nay";
		break;
}
?>